<?php
/**
 * 商场管理
 * @author Ice iceinto@mallog.com.cn
 */
class MarketModel extends BaseModel
{
	//自动验证
	protected $_validate = array(
			array('name', 'require', '名称必须！',self::MUST_VALIDATE),
			array('province', 'require', '省必须！',self::MUST_VALIDATE),
			array('city', 'require', '市必须！',self::MUST_VALIDATE),
			array('area', 'require', '区必须！',self::MUST_VALIDATE),
			array('cbd', 'require', '商区必须！',self::MUST_VALIDATE),
			array('initial', 'require', '首字母必须！',self::MUST_VALIDATE),
			array('image', 'require', '图片必须！',self::VALUE_VALIDATE),
			array('b_time', 'require', '营业时间必须！',self::MUST_VALIDATE),
			array('intr', 'require', '简介必须！',self::MUST_VALIDATE),
			array('name','','名称已经存在！',0,'unique',self::MODEL_BOTH),
	);
	public function getAllData ()
	{
		return $this->field(
				'm_market.id,
				m_market.name,
				m_province.`name` as pName,
				m_city.`name` as cName,
				m_area.`name` aName,
				m_bus.name as busName' )
				->join('LEFT JOIN m_city ON m_market.city = m_city.`code`')
				->join('LEFT JOIN m_province ON m_market.province = m_province.`code`')
				->join('LEFT JOIN m_area ON m_market.area = m_area.`code`')
				->join('LEFT JOIN m_bus ON m_bus.id = m_market.cbd')
				->order('m_market.id DESC')
				->select();
	}
	public function getOnly ($map)
	{
		return $this->field(
				'm_market.id,
				m_market.name,
				m_market.province,
				m_market.city,
				m_market.area,
				m_market.cbd,
				m_market.b_time,
				m_market.intr,
				m_market.initial,
				m_market.image,
				m_market.contact,
				m_province.`name` as pName,
				m_city.`name` as cName,
				m_area.`name` aName,
				m_bus.name as busName')
				->join('LEFT JOIN m_city ON m_market.city = m_city.`code`')
				->join('LEFT JOIN m_province ON m_market.province = m_province.`code`')
				->join('LEFT JOIN m_area ON m_market.area = m_area.`code`')
				->join('LEFT JOIN m_bus ON m_bus.id = m_market.cbd')
				->where($map)
				->find();
	}
}
?>